#include "StarMgr.h"


StarMgr::StarMgr() :m_pStarAPool(nullptr),
		m_pStarBPool(nullptr),
		m_pStarCPool(nullptr),
		m_pStarDPool(nullptr),
		m_pStarEPool(nullptr)
{

}

StarMgr::~StarMgr()
{

}

bool StarMgr::Init()
{
	m_pStarAPool = new ObjectPool<StarA>(20, false);
	MMO_ASSERT(m_pStarAPool);
	m_pStarBPool = new ObjectPool<StarB>(20, false);
	MMO_ASSERT(m_pStarBPool);
	m_pStarCPool = new ObjectPool<StarC>(20, false);
	MMO_ASSERT(m_pStarCPool);
	m_pStarDPool = new ObjectPool<StarD>(20, false);
	MMO_ASSERT(m_pStarDPool);
	m_pStarEPool = new ObjectPool<StarE>(20, false);
	MMO_ASSERT(m_pStarEPool);

	return true;
}

void StarMgr::UnInit()
{
	MMO_DELETE(m_pStarAPool);
	MMO_DELETE(m_pStarBPool);
	MMO_DELETE(m_pStarCPool);
	MMO_DELETE(m_pStarDPool);
	MMO_DELETE(m_pStarEPool);
}

IStar *StarMgr::MakeStarObj(int8_t bytype)
{
	IStar *pstar = nullptr;
	switch (bytype)
	{
	case (int8_t)EDupStarType::EDupStarType_A:
		{
			pstar = m_pStarAPool->MallocObj();
		}
		break;
	case (int8_t)EDupStarType::EDupStarType_B:
		{
			pstar = m_pStarBPool->MallocObj();
		}
		break;
	case (int8_t)EDupStarType::EDupStarType_C:
		{
			pstar = m_pStarCPool->MallocObj();
		}
		break;
	case (int8_t)EDupStarType::EDupStarType_D:
		{
			pstar = m_pStarDPool->MallocObj();
		}
		break;
	case (int8_t)EDupStarType::EDupStarType_E:
		{
			pstar = m_pStarEPool->MallocObj();
		}
		break;
	default:
		break;
	}

	return pstar;
}

void StarMgr::FreeStarObj(IStar *pstar)
{
	if (nullptr == pstar)
	{
		return;
	}
	int8_t bytype = pstar->starType();
	switch (bytype)
	{
	case (int8_t)EDupStarType::EDupStarType_A:
		{
			m_pStarAPool->FreeObj((StarA*)pstar);
		}
		break;
	case (int8_t)EDupStarType::EDupStarType_B:
		{
			m_pStarBPool->FreeObj((StarB*)pstar);
		}
		break;
	case (int8_t)EDupStarType::EDupStarType_C:
		{
			m_pStarCPool->FreeObj((StarC*)pstar);
		}
		break;
	case (int8_t)EDupStarType::EDupStarType_D:
		{
			m_pStarDPool->FreeObj((StarD*)pstar);
		}
		break;
	case (int8_t)EDupStarType::EDupStarType_E:
		{
			m_pStarEPool->FreeObj((StarE*)pstar);
		}
		break;
	default:
		{
			LogErrFmtPrint("[logic] StarMgr::FreeStarObj... unkonwn star type ......type:%d ", bytype);
			MMO_DELETE(pstar);
		}
		break;
	}
}

bool StarMgr::RecycleStar(IStar *pStar)
{
	if (nullptr == pStar)
	{
		return false;
	}
	pStar->uninit();
	FreeStarObj(pStar);

	return true;
}